﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Shell.Ioc;
using Shell.Build.Lifetime;
using Shell.Advanced;
//using Shell.Advanced;

namespace Shell.Demo
{
    class Program
    {
        static void Main(string[] args)
        {
            IShell shell = new DefaultShell();
            shell.Attach(new ShellRegistrationRecorderExtension());
            shell.Attach(new IocBuildersExtension());
            A a = new A();
            TestClass t = new TestClass(a);


            //shell.Register(null, typeof(ITestInterface), typeof(TestClass), null);
            shell.Register("2", typeof(ITestInterface), typeof(TestClass2), null);
            shell.Register(null, typeof(IA), a, new SingletonLifttimePolicy());
            shell.Register(null, typeof(ITestInterface), t, new SingletonLifttimePolicy());
            var tests = IShellAdvancedHelper.Resolve(shell, typeof(ITestInterface));
            var instanse = shell.Resolve(null, typeof(ITestInterface));
            var i1 = instanse as ITestInterface;
            i1.Name = "i1";

            var instanse2 = shell.Resolve(null, typeof(ITestInterface));
            var i2 = instanse2 as ITestInterface;
            i2.Name = "i2";

            i1.Do();
            i2.Do();
        }
    }

    class TestClass : ITestInterface
    {
        private IA a;

        public TestClass(IA a)
        {
            this.a = a;
        }

        public string Name { get; set; }

        public void Do()
        {
            Console.WriteLine(Name + " is doing");
            this.a.Do();
            Console.WriteLine(Name + " has done");
        }
    }

    class TestClass2 : ITestInterface
    {
        public void Do()
        {
            Console.WriteLine("TestClass2 is doing");
        }

        public string Name { get; set; }
    }

    interface ITestInterface
    {
        string Name { get; set; }
        void Do();
    }

    interface IA
    {
        void Do();
    }

    class A : IA
    {
        private int i = 0;

        public void Do()
        {
            i++;
            Console.WriteLine(i + " gaga");
        }
    }
}
